//人员管理相关配置
import { nanoid } from "nanoid";
import axios from 'axios'
export default {
    namespaced: true,
    actions: {
        addPersonWang(context, name) {
            if (name.indexOf("王") === 0) {
                context.commit("ADD_PERSON", name)
            } else {
                alert("添加的人必须姓王！")
            }
        },
        addServer(context) {
            axios({
                method: "GET",
                url: "https://api.uixsj.cn/hitokoto/get?type=social"
            }).then((response) => {
                context.commit("ADD_PERSON", response.data)
            }, (error) => {
                alert(error.message)
            });
        }
    },
    mutations: {
        ADD_PERSON(state, name) {
            const personObj = { id: nanoid(), name };
            state.personList.unshift(personObj);
        },
    },
    state: {
        personList: [
            { id: "001", name: "张三" }
        ]
    },
    getters: {
        firstPersonName(state) {
            return state.personList[0].name
        }
    }
}